/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package conversorcsvxml;

import java.io.*;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Marcel
 */
public class DocumentoCSV {
    
    private List<String[]> doc;
    
    public DocumentoCSV (List<String[]> doc) {
        this.doc = doc;
    }
    
    public void save () {
        OutputStream output = null;
        OutputStreamWriter writer = null;
        BufferedWriter bw = null;
        try  {
            output = new FileOutputStream("notas.csv", false);
            writer = new OutputStreamWriter(output);
            bw = new BufferedWriter(writer);
            for (String[] linha : doc) {
                for (int i = 0; i < linha.length - 1; i++) {
                    bw.write(linha[i] + ";");
                }
                bw.write(linha[linha.length - 1] + "\n");
            }
        }
        catch (FileNotFoundException ex) {
            System.out.println("error1csv");
        }
        catch (IOException io) {
            System.out.println("error2xml");
        }
        finally {
            try {
                output.close();
                writer.close();
                //bw.close();
            } catch (IOException ex) {
                Logger.getLogger(DocumentoCSV.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    }
    
}
